package cn.kgc.itrip.biz.controller;

import cn.kgc.itrip.beans.common.ServerResponse;
import cn.kgc.itrip.beans.model.vo.ItripAddCommentVO;
import cn.kgc.itrip.beans.model.vo.ItripSearchCommentVo;
import cn.kgc.itrip.biz.service.IHotelService;
import cn.kgc.itrip.biz.service.itripCommentService;
import cn.kgc.itrip.mapper.itripImage.ItripImageMapper;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author 阿泽
 */
@Controller
@RequestMapping("/api/comment")
public class SystemCommentController {
    @Resource
    private ItripImageMapper itripImageMapper;
    @Resource
    private IHotelService iHotelService;
    @Resource
    private itripCommentService itripCommentService;
    private String imgName;
    private HttpServletRequest request;

    /**
     * . 查询出游类型列表
     * GET /api/comment/gettraveltype
     */
    @RequestMapping(value = "/gettraveltype", method = RequestMethod.GET)
    @ResponseBody
    public ServerResponse gettraveltype() {
        return itripCommentService.gettraveltype();
    }

    /**
     * 根据targetId查询评论照片(type=2)
     * GET /api/comment/getimg/{targetId}
     */

    @RequestMapping(value = "/getimg/{targetId}", method = RequestMethod.GET)
    @ResponseBody
    public ServerResponse getimg(@PathVariable String targetId) {
        return itripCommentService.getimg(targetId, "2");
    }

    /**
     * 新增评论接口
     * POST /api/comment/add
     */

    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse add(@RequestBody ItripAddCommentVO itripAddCommentVO,HttpServletRequest request) throws Exception {
        return itripCommentService.add(itripAddCommentVO,request);
    }

    /**
     * GET /api/comment/gethoteldesc/{hotelId}
     * 获取酒店相关信息（酒店名称、酒店星级）
     */
    @RequestMapping(value = "/gethoteldesc/{hotelId}", method = RequestMethod.GET)
    @ResponseBody
    public ServerResponse gethoteldesc(@PathVariable String hotelId) {
        return iHotelService.gethoteldesc(hotelId);
    }

    /**
     * GET /api/comment/gethotelscore/{hotelId}
     * 据酒店id查询酒店平均分
     */

    @RequestMapping(value = "/gethotelscore/{hotelId}", method = RequestMethod.GET)
    @ResponseBody
    public ServerResponse gethotelscore(@PathVariable String hotelId) {
        return itripCommentService.gethotelscore(hotelId);
    }

    /**
     * GET/api/comment/getcount/{hotelId}
     * 根据酒店id查询各类评论数量
     */
    @RequestMapping(value = "/getcount/{hotelId}", method = RequestMethod.GET)
    @ResponseBody
    public ServerResponse getcount(@PathVariable String hotelId) {
        return itripCommentService.getcount(hotelId);
    }

    /**
     * 根据评论类型查询评论列表，并分页显示
     * POST /api/comment/getcommentlist
     */

    @RequestMapping(value = "/getcommentlist", method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse getcommentlist(@RequestBody ItripSearchCommentVo itripSearchCommentVO) throws Exception {
        return itripCommentService.getCommentList(itripSearchCommentVO);
    }



    /**
     * 图片上传接口
     * POST /api/comment/upload
     */
    @RequestMapping(value = "/upload", method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse upload(HttpServletRequest request) throws Exception {
       /* *//**
         * 上传图片
         *//*
        //图片上传成功后，将图片的地址写到数据库
        String filePath = "E:\\upload";//保存图片的路径
        //获取原始图片的拓展名
        String originalFilename = file.getOriginalFilename();
        //新的文件名字
        String newFileName = UUID.randomUUID() + originalFilename;
        //封装上传文件位置的全路径
        File targetFile = new File(filePath, newFileName);
        //把本地文件上传到封装上传文件位置的全路径
        file.transferTo(targetFile);*/
        return itripCommentService.upload(request);
    }


    /**
     * 图片删除接口
     * POST /api/comment/delpic
     */
//删除已经保存的文件
    @RequestMapping(value = "/delpic",method = RequestMethod.POST,produces = "application/json")
    @ResponseBody
    public ServerResponse delpic(@RequestParam String imgName, HttpServletRequest request)throws Exception
    {
        return itripCommentService.delpic(imgName,request);
    }


}
